# strs = ["10", "0001", "111001", "1", "0"]
# m = 5
# n = 3
strs = ["10", "0", "1"]
m = 1
n = 1
def findMaxForm(strs, m, n):
    dp=[[0 for _ in range((m+1)*(n+1))] for _ in range(len(strs))]
    #先处理第一个元素
    count0=strs[0].count('0')
    count1=strs[0].count('1')
    for i in range(m+1):
        for j in range(n+1):
            if i>=count0 and j>=count1:
                dp[0][i*(n+1)+j]=1
    #处理其余元素
    for i in range(1,len(strs)):
        #第几个字符串
        count0 = strs[i].count('0')
        count1 = strs[i].count('1')
        for j in range(m+1):
            for k in range(n+1):
                #先让本索引位置的dp状态转移矩阵和上一个索引位置的一样
                dp[i][j*(n+1)+k]=dp[i-1][j*(n+1)+k]
                if j>=count0 and k >=count1:
                    dp[i][j*(n+1)+k]=max(dp[i-1][j*(n+1)+k],dp[i-1][(j-count0)*(n+1)+(k-count1)]+1)
    return dp[len(strs)-1][m*(n+1)+n]
print(findMaxForm(strs,m,n))